package com.yanxu;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2024/11/12-2024
 * @Description: 子线程加入， main主线程在等待的过程中的状态
 */
public class JoinStates {
    public static void main(String[] args) throws InterruptedException {
        final Thread mainThread = Thread.currentThread();

        //定义子线程
        Thread thread1 = new Thread(new Runnable() {
            public void run() {
                Thread.State state = mainThread.getState();  //获取主线程的状态
                System.out.println("main线程的状态为："+ state);
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        thread1.start();
        thread1.join();  //子线程加入， main线程等待子线程执行完毕，等待过程中main线程为 main线程的状态为：WAITING 状态。
    }
}